package com.ykj.service.impl;

import cn.hutool.Hutool;
import cn.hutool.core.date.DateUtil;
import com.ykj.dto.CommentUser;
import com.ykj.dto.Result;
import com.ykj.entity.Comment;
import com.ykj.mapper.CommentMapper;
import com.ykj.service.CommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ykj.utils.MyUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Y2014188432
 * @since 2022-05-14
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Override
    public Result getCommentByPostsId(String postsId) {
        // 1 查数据库
        List<CommentUser> commentUserList = getBaseMapper().getMessage(postsId);
        // 2 返回
        return Result.ok(commentUserList);
    }

    @Override
    public Result createComment(Comment comment) {
        String id = MyUtils.get();
        comment.setUserid(id);
        comment.setCreateTime(DateUtil.formatDateTime(new Date()));
        // 1 保存
        System.out.println("comment = " + comment);
        save(comment);
        // 2 返回
        return Result.ok();


    }

    @Override
    public Result getAll() {
        List<Comment> commentList = query().list();
        return Result.ok(commentList);
    }
}
